<template>
	<view>
		<view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30">
			<u-form :model="model" ref="uForm" style="width: 100%;">
				<u-form-item label-width="130" label="设备类型:">
					<u-select v-model="equipShow" :list="type" @confirm="confirm"></u-select>
					<u-tag :text="getTyp(model.labelId)" @click="equipShow = true" />
				</u-form-item>
				<u-form-item label-width="130" label="题型:">
					<u-radio-group v-model="model.mode">
						<u-radio shape="circle" v-for="(item, index) in radioList" :key="index" :name="item.value">{{ item.name }}</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label-width="130" style="color:red" label="巡检内容:"><u-input v-model="model.subject" type="text" /></u-form-item>
				<u-form-item label-width="130" style="color:red" label="选项:"><u-input v-model="model.answer" placeholder="逗号分割(选项1,选项2)" type="text" /></u-form-item>
				<u-form-item label-width="130" label="排序:"><u-number-box v-model="model.sort"></u-number-box></u-form-item>
			</u-form>
		</view>
		<u-gap height="20"></u-gap>
		<view class="btn-line">
			<button class="landing" type="primary" style="width: 90%;" @click="bindConfirm">提交</button>
			</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			equipShow: false,
			model: {
				mode: 1,
				sort: 0
			},
			type: [],
			radioList: [
				{
					name: '文本',
					value: 1
				},
				{
					name: '单选',
					value: 2
				},
				{
					name: '多选',
					value: 3
				}
			]
		};
	},
	onLoad(option) {
		this.request({
			url: 'BaseLabel/pages',
			data: {
				limit: 0
			},
			success: res => {
				this.type = res.data;
			}
		});
	},
	methods: {
		getTyp(id) {
			let typ = this.type.find(m => m.value == id);
			if (typ != undefined) {
				return typ.label;
			} else {
				return '请选择分类';
			}
		},
		confirm(e) {
			if (e.length > 0) {
				this.model.labelId = e[0].value;
			}
		},
		bindConfirm() {
			if (this.model.subject == undefined || this.model.subject == '') {
				this.$u.toast('请选择巡检内容');
				return;
			}
			if (this.model.answer == undefined || this.model.answer == '') {
				this.$u.toast('请输入选项');
				return;
			}
			this.request({
				url: 'EamItem/add',
				method: 'POST',
				data: this.model,
				success: res => {
					if (res.code == 200) {
						uni.navigateBack();
					} else {
						this.$u.toast(res.msg);
					}
				}
			});
		}
	}
};
</script>

<style lang="scss">
	.landing{
		height: 84upx;
		line-height: 84upx;
		border-radius: 44upx;
		font-size: 32upx;
		background: linear-gradient(left,#FF978D, #FFBB69);
	}
</style>
